package com.itheima.dao.system;

import com.itheima.domain.system.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface DeptDao {
    @Select("select * from ss_dept")
    @Results(id = "deptResults", value = {
            @Result(property = "id", column = "dept_id"),
            @Result(property = "deptName", column = "dept_name"),
            @Result(property = "parentId", column = "parent_id"),
            @Result(property = "state", column = "state"),
            @Result(
                    property = "parent",//表示给Dept对象中的parent属性赋值
                    column = "parent_id",
                    javaType = Dept.class,//parent属性表示的类型
                    //把parent_id这一列的值传给当前方法，当前方法执行完毕后会返回Dept对象，然后将返回的对象赋值给parent属性
                    one = @One(select = "com.itheima.dao.system.DeptDao.findById")
            )
    })
    List<Dept>findAll()throws Exception;
    @Select("select *from ss_dept where dept_id=#{id}")
    @ResultMap("deptResults")
    Dept findById(String id)throws Exception;
    @Insert("INSERT INTO `ss_dept` ( `dept_id`, `dept_name`, `parent_id`, `state` ) VALUES ( #{id},#{deptName},#{parentId},#{state} )")
    int save(Dept dept)throws Exception;
    @Update("UPDATE `ss_dept` SET `parent_id` = #{parentId}, `state` = #{state} WHERE `dept_id` = #{id}")
    int update(Dept dept)throws Exception;
    @Delete("delete from ss_dept where dept_id=#{id}")
    int delete(String id)throws Exception;

}
